{% embed 'Embed/table_embed.html.twig' %}
    {% import 'Import/app_import.html.twig' as appImport %}

    {% set columns = {'name': true, 'primary_shards': true, 'replicas': true, 'documents': true, 'documents_deleted': false, 'primary_size': true, 'total_size': false, 'status': true, 'health': true, 'system': true, 'creation_date': true} %}

    {% set sortUrl = path('indices', app.request.query.all|filter((v, k) => k != 'sort')) %}

    {% block thead %}
        <tr>
            {% for column, display in columns %}
                {% if true == display %}
                    {% if 'name' == column %}
                        <th>
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'index', 'title': 'name'|trans, 'default': ':asc'})}}
                        </th>
                    {% endif %}

                    {% if 'primary_shards' == column %}
                        <th>
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'pri', 'title': 'primary_shards'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'replicas' == column %}
                        <th>
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'rep', 'title': 'replicas'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'documents' == column %}
                        <th>
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'docs.count', 'title': 'documents'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'documents_deleted' == column %}
                        <th class="d-none d-xl-table-cell">
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'docs.deleted', 'title': 'documents_deleted'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'primary_size' == column %}
                        <th class="d-none d-xl-table-cell">
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'pri.store.size', 'title': 'primary_size'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'total_size' == column %}
                        <th class="d-none d-xl-table-cell">
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'store.size', 'title': 'total_size'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'status' == column %}
                        <th class="d-none d-xl-table-cell">
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'status', 'title': 'status'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'health' == column %}
                        <th>
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'health', 'title': 'health'|trans})}}
                        </th>
                    {% endif %}

                    {% if 'system' == column %}
                        <th class="d-none d-xl-table-cell">
                            {{ 'system'|trans }}
                        </th>
                    {% endif %}

                    {% if 'creation_date' == column %}
                        <th class="d-none d-xl-table-cell">
                            {{ appImport.sort({'cat_sort': cat_sort, 'url': sortUrl, 'sort': 'creation.date.string', 'title': 'creation_date'|trans})}}
                        </th>
                    {% endif %}
                {% endif %}
            {% endfor %}
        </tr>
    {% endblock %}

    {% block tbody %}
        {% for row in indices.rows %}
            <tr>
                {% for column, display in columns %}
                    {% if true == display %}
                        {% if 'name' == column %}
                            <td>
                                <a class="{{ theme_link_primary }}" href="{{ path('indices_read', {'index': row.name}) }}">{{ row.name }}</a>
                                {% if row.aliases %}
                                    <br><small>{{ row.aliases|keys|join(', ') }}</small>
                                {% endif %}
                            </td>
                        {% endif %}

                        {% if 'primary_shards' == column %}
                            <td>
                                {{ row.primaryShards }}
                            </td>
                        {% endif %}

                        {% if 'replicas' == column %}
                            <td>
                                {{ row.replicas }}
                            </td>
                        {% endif %}

                        {% if 'documents' == column %}
                            <td>
                                {{ row.documents }}
                            </td>
                        {% endif %}

                        {% if 'documents_deleted' == column %}
                            <td class="d-none d-xl-table-cell">
                                {{ row.documentsDeleted }}
                            </td>
                        {% endif %}

                        {% if 'primary_size' == column %}
                            <td class="d-none d-xl-table-cell">
                                {{ row.primarySize|human_filesize }}
                            </td>
                        {% endif %}

                        {% if 'total_size' == column %}
                            <td class="d-none d-xl-table-cell">
                                {{ row.totalSize|human_filesize }}
                            </td>
                        {% endif %}

                        {% if 'status' == column %}
                            <th class="d-none d-xl-table-cell">
                                {% if row.status %}
                                    {{ appImport.badge({'title': row.status|trans, 'context': row.status}) }}
                                {% endif %}
                            </td>
                        {% endif %}

                        {% if 'health' == column %}
                            <td>
                                {% if row.health %}
                                    {{ appImport.badge({'title': row.health|trans, 'context': row.health}) }}
                                {% endif %}
                            </td>
                        {% endif %}

                        {% if 'system' == column %}
                            <td class="d-none d-xl-table-cell">
                                {{ appImport.badge({'title': ('boolean.' ~ row.isSystem)|trans, 'context': row.isSystem}) }}
                            </td>
                        {% endif %}

                        {% if 'creation_date' == column %}
                            <td class="d-none d-xl-table-cell">
                                {{ row.creationDate|human_datetime }}
                            </td>
                        {% endif %}
                    {% endif %}
                {% endfor %}
            </tr>
        {% endfor %}
    {% endblock %}
{% endembed %}
